﻿using Gobang.DataServer.Models;
using Gobang.ToolClass;

namespace Gobang.DataServer.DbOperation
{
    public class UserInfoServer : DataServerBase
    {

        public bool RegisterUser(Gb_UserInfo userInfo)
        {
            lock (_locker)
            {
                var first = DictionaryServer.GetInfoWithGroupName("UserInfoServer.Accountnumber").FirstOrDefault();
                userInfo.Id = this.Id;
                userInfo.Accountnumber = first.Value;
                userInfo.CreateTime = DateTime.Now;
                var status = Db.Insertable(userInfo).ExecuteCommand() > 0;
                if (status)
                {
                    long num = first.Value.ToInt64();
                    ++num;
                    first.Value = num.ToString();
                    DictionaryServer.Update(first);
                }

                return status;
            }
        }
        private readonly object _locker = new object();
        protected string Accountnumber
        {
            get
            {
                lock (_locker)
                {
                    return DictionaryServer.GetInfoWithGroupName("UserInfoServer.Accountnumber").FirstOrDefault().Value;
                }
            }
        }
        public Gb_UserInfo Login(string acc, string pwd)
        {
            return Db.Queryable<Gb_UserInfo>().First(t => t.Accountnumber == acc && t.Password == pwd);
        }
    }
}
